﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.DAL.Providers
{
    public class StatiticsProvider
    {
        Fady_HanyDbEntities1 Context;

        public StatiticsProvider()
        {
            Context = new Fady_HanyDbEntities1();
        }

        public StatObjects.StatData GetData(int? StockID, DateTime? From, DateTime? To)
        {
            StatObjects.StatData Data = new StatObjects.StatData();
            List<Order> temp = (from Orders in Context.Orders
                                select Orders).ToList();

            Data.OrderBuyNum = temp.Where(t => t.Type == 0).Count();
            Data.OrderSellNum = temp.Where(t => t.Type == 1).Count();

            Data.CreditFromOrder = (decimal)(from O in Context.Orders
                                             where O.Type == 0
                                             select O).ToList().Sum(t => t.PaidPrice);

            Data.DebitFromOrder = (decimal)(from O in Context.Orders
                                            where O.Type == 1
                                            select O).ToList().Sum(t => t.PaidPrice);

            Data.ItemsNeeded = (from i in Context.StockItems
                                where i.Count <= i.MinCount
                                join s in Context.Items on i.ItemID equals s.ID
                                select new StatObjects.ItemData()
                                {
                                    Count = (int)i.Count,
                                    ItemName = s.Name

                                }
                                ).ToList();
            var x = (from OI in Context.OrderItems
                     select OI).ToList();

            var y = x.Distinct().ToList();

            for (int i = 0; i < y.Count(); i++)
            {
            }

            return Data;
        }
    }
}
